-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tab-completion for paths #45
base: master
Are you sure you want to change the base?
Conversation
Supported commands: all commands accepting a `path` argument (ls, rm, mv, edit, show). Caveats Completions must match exact structure of paths. As a result, it doesn't: - support db-prefixes - support case-insensitivty - support regexes Additional changes - Add `login` command (for explicit caching, when `zenity` is missing) - Remove extra '' around form label in `zenity` - Remove period from error message - Fix incorrect name being passed to default section prompt - Handle more cases in `decompose_path` + return tuple - Fix `info_parser` comment
@Evidlo I've yet to update the documentation with how to set it up, but please have a look/try it out. I'll update the docs when we've settled on something. |
In the meantime, if you're not familiar with |
I did some experimentation with prompting for the password during the completion to eliminate the need for
#!/bin/env python3
from getpass import getpass
import argcomplete, argparse
def path_completer(prefix, parsed_args, **kwargs):
password = getpass('\nInput Password:')
if password == 'password':
return ['helloworld', 'foobar']
parser = argparse.ArgumentParser()
patharg = parser.add_argument('path', metavar='PATH', type=str, help='item path')
patharg.completer = path_completer
argcomplete.autocomplete(parser)
args = parser.parse_args()
print(f'selected item: {args.path}') And for testing:
It's not fully working, as you have to hit enter twice for some reason after entering a password and the prompt line isn't redrawn when the completion is finished. Also, argcomplete hijacks stdout so I had to abuse Ideally, tab completion when entering a password would look something like this:
|
Supported commands: all commands accepting a
path
argument (ls, rm, mv, edit, show).Caveats
Completions must match exact structure of paths. As a result, it doesn't:
Additional changes
login
command (for explicit caching, whenzenity
is missing)zenity
decompose_path
+ return tupleinfo_parser
commentCloses #44